//
//  MenuViewController.m
//  SuperBeacon
//
//  Created by kys-2 on 15-3-30.
//  Copyright (c) 2015年 孙晓林. All rights reserved.
//

#import "MenuViewController.h"
#import "PublicMethodManager.h"
#import "PKRevealController.h"
#import "T4Marco.h"

@interface MenuViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *menuTableView;
@property (weak, nonatomic) IBOutlet UIImageView *backgroundImageView;

@end

@implementation MenuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _backgroundImageView.image = [[PublicMethodManager sharedInstance] blurryImage:[UIImage imageNamed:@"background"] withBlurLevel:kBlurLevel];
    
    _menuTableView.delegate = self;
    _menuTableView.dataSource = self;
    _menuTableView.opaque = NO;
    _menuTableView.backgroundColor = [UIColor clearColor];
    _menuTableView.separatorStyle = NO;
    _menuTableView.bounces = NO;
    [self.revealController setMinimumWidth:240 maximumWidth:260 forViewController:self];
}

#pragma mark - UITableView Delegate

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.textColor = HEXCOLOR(0xebebf3);
    cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:19];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)sectionIndex
{
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex
{
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"Cell";
    NSArray *titles, *images;
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    
    titles = @[@"发现", @"我的", @"语言", @"搜索", @"摇一摇"];
    images = @[@"sidebar_find", @"sidebar_mine", @"sidebar_language", @"sidebar_search", @"sidebar_shake"];
    cell.imageView.image = [UIImage imageNamed:images[indexPath.row]];
    
    CGSize imageSize = CGSizeMake(19, 19);
    UIGraphicsBeginImageContextWithOptions(imageSize, NO, UIScreen.mainScreen.scale);
    CGRect imageRect = CGRectMake(0.0, 0.0, imageSize.width, imageSize.height);
    [cell.imageView.image drawInRect:imageRect];
    cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    cell.textLabel.text = titles[indexPath.row];
    
    UIView *selectedBackground = [UIView new];
    selectedBackground.alpha = 0.7;
    selectedBackground.backgroundColor = HEXCOLOR(0xff5d5d);
    [cell setSelectedBackgroundView:selectedBackground];
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
